package com.cction.comm;

import com.cction.entry.EtcBean;
import com.cction.entry.HouseBean;

import java.util.ArrayList;

/**
 * 组合贷款
 */
public class AverageCapitalCombination {


    /**
     * 等额本息
     *
     * @param houseBean 组合信息
     * @return
     */
    public static EtcBean getCombinationInterests(HouseBean houseBean) {
        EtcBean etcBean = new EtcBean();

        EtcBean etcInterests_s = AverageCapitalPlusInterestUtils.getEtcInterests(houseBean.sLoan * 10000, houseBean.sRate / 100, houseBean.time);
        EtcBean etcInterests_g = AverageCapitalPlusInterestUtils.getEtcInterests(houseBean.gLoan * 10000, houseBean.gRate / 100, houseBean.time);

        //每月差额
        etcBean.poor = 0;
        //每月还款金额
        etcBean.monthMenoy = etcInterests_s.monthMenoy + etcInterests_g.monthMenoy;
        //总本金
        etcBean.menoy = houseBean.gLoan + houseBean.sLoan;
        //总利息
        etcBean.insterest = etcInterests_s.insterest + etcInterests_g.insterest;
        //总还款
        etcBean.total = etcInterests_s.total + etcInterests_g.total;
        //还款期数
        etcBean.time = houseBean.time * 12;

        ArrayList<EtcBean.Childen> list_s = etcInterests_s.childens;
        ArrayList<EtcBean.Childen> list_g = etcInterests_g.childens;

        ArrayList<EtcBean.Childen> curList = new ArrayList<>();
        int size = list_g.size();
        for (int i = 0; i < size; i++) {
            EtcBean.Childen childen = new EtcBean.Childen();
            EtcBean.Childen childen_s = list_s.get(i);
            EtcBean.Childen childen_g = list_g.get(i);

            childen.total = childen_g.total + childen_s.total;
            childen.money = childen_g.money + childen_s.money;
            childen.insterest = childen_g.insterest + childen_s.insterest;
            curList.add(childen);
        }

        etcBean.childens = curList;
        return etcBean;
    }


    /**
     * 等额本金
     *
     * @param houseBean 组合信息
     * @return
     */
    public static EtcBean getCombinationMenoys(HouseBean houseBean) {
        EtcBean etcBean = new EtcBean();

        EtcBean etcMenoys_s = AverageCapitalUtils.getEtcMenoys(houseBean.sLoan * 10000, houseBean.sRate / 100, houseBean.time);
        EtcBean etcMenoys_g = AverageCapitalUtils.getEtcMenoys(houseBean.gLoan * 10000, houseBean.gRate / 100, houseBean.time);

        //每月差额
        etcBean.poor = etcMenoys_s.poor + etcMenoys_g.poor;
        //每月还款金额
        etcBean.monthMenoy = etcMenoys_s.monthMenoy + etcMenoys_g.monthMenoy;
        //总本金
        etcBean.menoy = houseBean.gLoan + houseBean.sLoan;
        //总利息
        etcBean.insterest = etcMenoys_s.insterest + etcMenoys_g.insterest;
        //总还款
        etcBean.total = etcMenoys_s.total + etcMenoys_g.total;
        //还款期数
        etcBean.time = houseBean.time * 12;

        ArrayList<EtcBean.Childen> list_s = etcMenoys_s.childens;
        ArrayList<EtcBean.Childen> list_g = etcMenoys_g.childens;

        ArrayList<EtcBean.Childen> curList = new ArrayList<>();
        int size = list_g.size();
        for (int i = 0; i < size; i++) {
            EtcBean.Childen childen = new EtcBean.Childen();
            EtcBean.Childen childen_s = list_s.get(i);
            EtcBean.Childen childen_g = list_g.get(i);

            childen.total = childen_g.total + childen_s.total;
            childen.money = childen_g.money + childen_s.money;
            childen.insterest = childen_g.insterest + childen_s.insterest;
            curList.add(childen);
        }

        etcBean.childens = curList;
        return etcBean;
    }

}
